package net.sunzc.hwfacetest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;
import net.sunzc.hwfacetest.utils.FileUtils;
import net.sunzc.hwfacetest.utils.MyLog;
import net.sunzc.takephoto.FaceRecognizeActivity;
import net.sunzc.takephoto.TAddFaceDelog;

public class MainActivity extends Activity {

    private static final int FACE_RECOGNIZE = 1;
    private static final int ADD_FACE = 2;
    private static final int T_FACE_RECOGNIZE = 3;
    private static final int T_ADD_FACE = 4;
    private static final String TAG = "Main";
    private String faceData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        faceData = FileUtils.readTxtFile("/sdcard/takePhotoFeature");
//        MyLog.i(TAG, "读出的faceData长度:" + faceData.length() + "内容:" + faceData);
    }

    public void recognize(View view) {
        if (TextUtils.isEmpty(faceData)) {
            Toast.makeText(this, "faceData为空", Toast.LENGTH_SHORT).show();
            return;
        }
        FaceDelog.faceRecognize(this, faceData, FACE_RECOGNIZE);
    }

    public void collect(View view) {
        AddFaceDelog.addFace(this, "HWFaceTest", ADD_FACE);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case ADD_FACE:
                faceData = AddFaceDelog.getFaceData(resultCode, data);
                MyLog.i(TAG, "faceData:" + faceData.length() + "内容:" + faceData);
                FileUtils.writeFile("/sdcard/HWFaceTestFeature", faceData);
                break;
            case T_ADD_FACE:
                faceData = TAddFaceDelog.getFaceData(resultCode, data);
                break;
        }
    }

    public void takePhotoRecognize(View view) {
        if (TextUtils.isEmpty(faceData)) {
            Toast.makeText(this, "人脸数据空", Toast.LENGTH_SHORT).show();
            return;
        }
        FaceRecognizeActivity.open(this, faceData);
    }

    public void takePhotoCollect(View view) {
        TAddFaceDelog.openActivity(this, "testHWFace", T_ADD_FACE);
    }
}
